package com.opensky.qatest.ui.component.common;

import org.openqa.selenium.By;

import com.opensky.qatest.util.selenium.WebDriverWrapper;

/*
 * AbstractJoinNag contains base locators, verifications 
 *
 * @author: Aliakse_Khursevich (hursevich@gmail.com)
 * @version: 1.0
 * 
 */
public class AbstractJoinNag {

    // ************************ Locators ************************

    private static final String CATEGORIES = "//div[@id='join-nag']//div[@class='category-follow']";

    private static final String NAME_FIELD = "//div[@id='join-nag']//input[@id='registration_user_firstName']";

    private static final String EMAIL_FIELD = "//div[@id='join-nag']//input[@id='registration_user_email']";

    private static final String PASSWORD_FIELD = "//div[@id='join-nag']//input[@id='registration_user_plainPassword']";

    private static final String START_SHOPPING_BTN = "//div[@id='join-nag']//input[@name='submit']";

    private static final String TERMS_LINK = "//div[@id='join-nag']//a[@href='http://www2.opensky.com/policies/terms']";

    private static final String STEP2JOIN_1 = "//ol/li[@class='access-sales']";

    private static final String STEP2JOIN_2 = "//ol/li[@class='check-inbox']";

    private static final String STEP2JOIN_3 = "//ol/li[@class='happiness-guaranteed']";

    private static final String INVALID_EMAIL_ALERT = "//div[@id='join-nag']//label[@for='registration_user_email' and contains(., 'Please provide valid email address.')]";

    private static final String EMPTY_PASSWORD_ALERT = "//div[@id='join-nag']//label[@for='registration_user_plainPassword' and contains(., 'Please provide a password.')]";

    private static final String SHORT_PASSWORD_ALERT = "//div[@id='join-nag']//label[@for='registration_user_plainPassword' and contains(., 'Your password is too short. It must have 6 characters or more.')]";

    private static final String HEALTH_CHECKBOX = "//div[@id='join-nag']//input[@id='registration_categoryFollow_healthy-living']";

    private static final String STYLE_CHECKBOX = "//div[@id='join-nag']//input[@id='registration_categoryFollow_style']";

    private static final String FOOD_CHECKBOX = "//div[@id='join-nag']//input[@id='registration_categoryFollow_food']";

    private static final String DESIGN_CHECKBOX = "//div[@id='join-nag']//input[@id='registration_categoryFollow_home-design']";

    private final WebDriverWrapper driver;

    public AbstractJoinNag(WebDriverWrapper driver) {
	this.driver = driver;
    }

    // ************************ Actions **************************

    public void signUp(String email, String password) {

	driver.waitAndSendKeys("EMAIL_FIELD", By.xpath(EMAIL_FIELD), email);
	driver.waitAndSendKeys("PASSWORD_FIELD", By.xpath(PASSWORD_FIELD), password);
	driver.waitAndClick("START_SHOPPING_BTN", By.xpath(START_SHOPPING_BTN));
    }

    public void checkCategories() {
	driver.waitAndClick("HEALTH_CHECKBOX", By.xpath(HEALTH_CHECKBOX));
	driver.waitAndClick("STYLE_CHECKBOX", By.xpath(STYLE_CHECKBOX));
	driver.waitAndClick("FOOD_CHECKBOX", By.xpath(FOOD_CHECKBOX));
	driver.waitAndClick("DESIGN_CHECKBOX", By.xpath(DESIGN_CHECKBOX));
    }

    // ************************ Validations **************************

    public boolean isBaseJoinNagElementsPresent() {

	driver.waitAndCheckElementPresent("NAME_FIELD", By.xpath(NAME_FIELD));
	driver.waitAndCheckElementPresent("EMAIL_FIELD", By.xpath(EMAIL_FIELD));
	driver.waitAndCheckElementPresent("PASSWORD_FIELD", By.xpath(PASSWORD_FIELD));
	driver.waitAndCheckElementPresent("CATEGORIES", By.xpath(CATEGORIES));
	driver.waitAndCheckElementPresent("START_SHOPPING_BTN", By.xpath(START_SHOPPING_BTN));
	driver.waitAndCheckElementPresent("TERMS_LINK", By.xpath(TERMS_LINK));

	return true;
    }

    public boolean isStepsToJoinPresent() {
	driver.waitAndCheckElementPresent("STEP2JOIN_1", By.xpath(STEP2JOIN_1));
	driver.waitAndCheckElementPresent("STEP2JOIN_2", By.xpath(STEP2JOIN_2));
	driver.waitAndCheckElementPresent("STEP2JOIN_3", By.xpath(STEP2JOIN_3));
	return true;
    }

    public boolean isInvalidEmailAlertPresent() {
	driver.waitAndCheckElementPresent("INVALID_EMAIL_ALERT", By.xpath(INVALID_EMAIL_ALERT));
	return true;
    }

    public boolean isEmptyPasswordAlertPresent() {
	driver.waitAndCheckElementPresent("EMPTY_PASSWORD_ALERT", By.xpath(EMPTY_PASSWORD_ALERT));
	return true;
    }

    public boolean isShortPasswordPresent() {
	driver.waitAndCheckElementPresent("SHORT_PASSWORD_ALERT", By.xpath(SHORT_PASSWORD_ALERT));
	return true;
    }
}